package com.dinzeer.sjapadder.se;

import com.dinzeer.legendreliclib.lib.util.FastMakeEntityUtil;
import com.dinzeer.sjapadder.register.SjaSpecialEffectRegsitry;
import mods.flammpfeil.slashblade.SlashBlade;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.event.SlashBladeEvent;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;

@Mod.EventBusSubscriber
public class SoulDevouring extends SpecialEffect {
    public SoulDevouring() {
        super(30);
    }


    @SubscribeEvent
    public static void onDoingSlash(SlashBladeEvent.HitEvent event) {
        ISlashBladeState state=event.getSlashBladeState();
        if ((event.getUser() instanceof Player player)){
            if (!state.hasSpecialEffect(SjaSpecialEffectRegsitry.SoulDevouring.getId()))return;
            // 获取周围20格范围内的生物
            AABB area = new AABB(player.getX() - 20, player.getY() - 20, player.getZ() - 20,
                    player.getX() + 20, player.getY() + 20, player.getZ() + 20);
            List<LivingEntity> entities = player.level().getEntitiesOfClass(LivingEntity.class, area);

            // 给予范围内生物发光效果
            for (LivingEntity entity : entities) {
                if (entity instanceof Player) continue;
                entity.hurt(FastMakeEntityUtil.DamageSourceToCreat(player, DamageTypes.MAGIC),
                        (float) Math.min((state.getKillCount()/100f)*(0.5+Math.min(state.getRefine()/10f,1.5f)),
                                state.getProudSoulCount()/100f)
                );
            }
        }
    }
}
